import QtQuick
import QtQuick.Controls.Fusion
import Gui.Global as G
import Backend as B

Button {
    id: control
    required property string iconName
    property color iconColor: palette.buttonText
    property var raduises: null
    property int iconSize: 16

    property color checkedColor: control.palette.button
    property color hoveredColor: Qt.alpha(checkedColor, 0.5)
    property color pressedColor: Qt.alpha(checkedColor, 0.8)
    property color backgroundColor: "#00000000"

    property alias cursorShape: mouseArea.cursorShape
    property alias raduis: _backgroundRect.radius

    property alias backgroundInstance: _backgroundRect
    property string tipName: ""

    contentItem: Label {
        id: _iconLb
        text: B.QtAwesomIconFont.charmap(control.iconName)
        font: B.QtAwesomIconFont.font(control.iconName.split(".")[0], control.iconSize)
        color: control.enabled ? (control.flat ? (control.hovered ? Qt.alpha(palette.highlight, 0.8) : control.iconColor) : control.iconColor) : Qt.darker(control.iconColor, 2)
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        padding: 2
    }
    background: Rectangle {
        id: _backgroundRect
        anchors.fill: parent
        color: control.enabled ? control.flat ? "transparent" : control.checked ? control.checkedColor : (control.pressed ? control.pressedColor : (control.hovered ? control.hoveredColor : control.backgroundColor)) : Qt.darker(control.backgroundColor, 1.5)
        topLeftRadius: control.raduises === null ? radius : control.raduises[0]
        topRightRadius: control.raduises === null ? radius : control.raduises[1]
        bottomRightRadius: control.raduises === null ? radius : control.raduises[2]
        bottomLeftRadius: control.raduises === null ? radius : control.raduises[3]
    }
    MouseArea {
        id: mouseArea
        anchors.fill: parent
        hoverEnabled: true
        acceptedButtons: Qt.NoButton
        MToolTip {
            font.pixelSize: 12
            text: control.tipName
            visible: control.hovered && control.tipName !== ""
            x: mouseArea.mouseX + 10
            y: mouseArea.mouseY + 10
        }
    }
}
